package TransactionImplementation

import (
	"SPC/Database"
	"SPC/Model"
	"time"
)

type PaydayTransaction struct {
	itsPayDate time.Time
	itsPaychecks map[int]Model.Paycheck
}

func NewPaydayTransaction(payDate time.Time)*PaydayTransaction{
	return &PaydayTransaction{
		payDate,
		make(map[int]Model.Paycheck),
	}
}

func (p *PaydayTransaction)Execute(){
	emplds := Database.GetPayrollDatabase().GetAllEmployeeIds()
	for _, v := range emplds {
		e := Database.GetPayrollDatabase().GetEmployee(v)
		if(e.GetEmpid() != 0){
			if(e.IsPayDate(p.itsPayDate)){
				pc := Model.NewPaycheck(e.GetPayPeriodStartDate(p.itsPayDate), p.itsPayDate)
				p.itsPaychecks[v] = *pc;
				e.Payday(*pc)
			}
		}
	}
}

func (p *PaydayTransaction)GetPaycheck(empid int)Model.Paycheck {
	return p.itsPaychecks[empid]
}

func (p *PaydayTransaction)GetPaycheckCount()int{
	return p.itsPayDate.Day()
}